package com.example.prison.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.prison.entity.SystemInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
* @author jiang
* @description 针对表【system_info】的数据库操作Mapper
* @createDate 2024-01-17 15:47:25
* @Entity com.example.prison.entity.SystemInfo
*/
@Mapper
public interface SystemInfoMapper extends BaseMapper<SystemInfo> {

    @Select("select * from system_info order by id desc")
    List<SystemInfo> get();

    @Insert("insert into system_info(refresh_time,gateway_address,gateway_port,pulse_solve,pulse_time,pulse_current,high_rated_voltage,rated_voltage,rated_current,defense) " +
            "values (#{refreshTime},#{gatewayAddress},#{gatewayPort},#{pulseSolve},#{pulseTime},#{pulseCurrent},#{highRatedVoltage},#{ratedVoltage},#{ratedCurrent},#{defense})")
    int add(SystemInfo record);

    @Delete("<script>delete from system_info where id in <foreach collection=\"ids\" item=\"item\" open=\"(\" separator=\",\" close=\")\">#{item} </foreach> </script>")
    void delete(@Param("ids") Integer[] ids);

    @Delete("delete from system_info")
    void deleteAll();

    @Update("update system_info set refresh_time=#{info.refreshTime},gateway_address=#{info.gatewayAddress},gateway_port=#{info.gatewayPort}," +
            "pulse_solve=#{info.pulseSolve},pulse_time=#{info.pulseTime},pulse_current=#{info.pulseCurrent},high_rated_voltage=#{info.highRatedVoltage}," +
            "rated_voltage=#{info.ratedVoltage},rated_current=#{info.ratedCurrent} ")
    int update(SystemInfo info, Integer id);

    @Update("update system_info set gateway_address=#{ip},gateway_port=#{port}")
    int updateIPAndPort(@Param("ip")String ip, @Param("port")Integer port);

    @Select("select * from system_info order by id desc LIMIT 1 ")
    SystemInfo one();

}




